package com.hankol.feature_wine_meal.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.viewpager.widget.PagerAdapter
import com.hankol.feature_wine_meal.R
import com.hankol.feature_wine_meal.bean.CharacteristicBean
import com.hankol.feature_wine_meal.view.HourHandBanner

/**
 * @author: 关忆北、
 * @date: 2022/6/13
 * @Des：头部轮播适配器
 */
class HeadBannerVpAdapter : PagerAdapter() {
    private var bean: ArrayList<CharacteristicBean> = arrayListOf()
    var hashMap: HashMap<Int, HourHandBanner> = hashMapOf()//记录下所有View，最多也就七八个
    fun setData(bean: ArrayList<CharacteristicBean>) {
        this.bean.clear()
        this.bean.addAll(bean);
        notifyDataSetChanged()
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val inflate = LayoutInflater.from(container.context).inflate(R.layout.item_head_banner, null)
        val mHhb = inflate.findViewById<HourHandBanner>(R.id.hhb)
        val tvCharacteristicTitle = inflate.findViewById<TextView>(R.id.tv_characteristic_title)
        tvCharacteristicTitle.paint.isFakeBoldText = true
        tvCharacteristicTitle.text = bean[position].name
        mHhb.setData(bean[position].appetizerDietList,bean[position].name)
        hashMap[position] = mHhb
        container.addView(inflate);
        return inflate

    }

    override fun getCount(): Int {
        return bean.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View)
    }

    override fun getItemPosition(`object`: Any): Int {
        return POSITION_NONE
    }
}